﻿Imports System.Web.UI
Imports System.Xml

Partial Class _114_UC04_020
    Inherits System.Web.UI.Page

    Public xdoc As New XmlDocument()

    Private Function createNode(ByVal eleName As String, ByVal eleValue As String) As XmlElement
        Dim newEle As XmlElement = xdoc.CreateElement(eleName)
        newEle.InnerText = eleValue
        Return newEle
    End Function
    Private Sub addTextnode(ByVal ele As XmlElement, ByVal text As String)
        Dim tn As XmlText = xdoc.CreateTextNode(text)
        ele.AppendChild(tn)
    End Sub
    Private Function fncReplaceNote(ByVal elenew As XmlElement, ByVal eleold As XmlElement) As XmlElement
        Dim newEle As XmlElement = xdoc.ReplaceChild(elenew, eleold)
        Return newEle
    End Function
    Private Sub replace(ByVal ele As XmlElement, ByVal text As String)
        Dim tn As XmlText = xdoc.CreateTextNode(text)
        ele.AppendChild(tn)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Try
            REM //load xml file			
            xdoc.Load(Server.MapPath("XMLViewInfo.xml"))

            Dim root As XmlNode = xdoc.DocumentElement
            root.RemoveChild(root.FirstChild)
            REM //them comments vao xml document
            Dim newEle As XmlElement = xdoc.CreateElement("Company")

            Dim child As XmlElement = createNode("name", txtTenCty.Text)
            newEle.AppendChild(child)

            child = createNode("address", txtDiachi.Text)
            newEle.AppendChild(child)

            child = createNode("logo", fuLogo.FileName)
            newEle.AppendChild(child)

            child = createNode("history", txtGioithieu.Text)
            newEle.AppendChild(child)

            child = createNode("telephone", txtDienthoai.Text)
            newEle.AppendChild(child)

            child = createNode("email", txtEmail.Text)
            newEle.AppendChild(child)

            child = createNode("date", txtDate.Text)
            newEle.AppendChild(child)

            root.AppendChild(newEle)

            xdoc.Save(Server.MapPath("XMLViewInfo.xml"))
            Dim intResult As Integer = MsgBox("Update Succesfull! Do you want to view info after udate?", MsgBoxStyle.OkCancel)
            If intResult = 1 Then

                Server.Transfer("UC04-010.aspx")

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
